package com.lims.algorithm.algset.graph.basic;

/**
 * <功能简述>图 邻接表
 * D 顶点中数据类型
 *
 * @author lims
 * @date 2020-08-19 11:53
 */
public abstract class GraphListAbs extends GraphAbs<VertexNode> {
    /**
     * 图 节点类
     */
    /*protected class VertexNode {
        *//**
         * 顶点数据信息
         *//*
        protected D data;
        *//**
         * 指向第一条依附该顶点的弧
         *//*
        protected EdgeNode firstEdge;

        public D getData() {
            return data;
        }

        public void setData(D data) {
            this.data = data;
        }

        public EdgeNode getFirstEdge() {
            return firstEdge;
        }

        public void setFirstEdge(EdgeNode firstEdge) {
            this.firstEdge = firstEdge;
        }
    }

    *//**
     * 边 类
     *//*
    protected class EdgeNode {
        *//**
         * 边所指向的顶点的位置
         *//*
        protected int iVex;
        *//**
         * 指向下一条弧的指针
         *//*
        protected EdgeNode nextEdge;

        public int getiVex() {
            return iVex;
        }

        public void setiVex(int iVex) {
            this.iVex = iVex;
        }

        public EdgeNode getNextEdge() {
            return nextEdge;
        }

        public void setNextEdge(EdgeNode nextEdge) {
            this.nextEdge = nextEdge;
        }
    }*/


    @Override
    protected int getPosition(VertexNode node) {
        for (int i = 0; i < vertes.length; i++) {
            if (vertes[i].equals(node)) {
                return i;
            }
        }
        return -1;
    }

    @Override
    public void print() {
        System.out.printf("List GraphUDG:\n");
        for (int i = 0; i < vertes.length; i++) {
            System.out.printf("%d(%c): ", i, vertes[i].data);
            EdgeNode edgeNode = vertes[i].firstEdge;
            while (edgeNode != null) {
                System.out.printf("%d(%c) ", edgeNode.iVex, vertes[edgeNode.iVex].data);
                edgeNode = edgeNode.nextEdge;
            }
            System.out.printf("\n");
        }
    }
}
